home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: genew@mindlink.bc.ca (Gene Wirchenko)
- Newsgroups: comp.lang.c
- Subject: Re: a question on "return"
- Date: Sun, 04 Feb 1996 17:58:47 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4f2s87$b6u@fountain.mindlink.net>
- References: <4f2ipq$kaf@srvr1.engin.umich.edu>
- NNTP-Posting-Host: line200.nwm.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- cjlin@news-server.engin.umich.edu (Chih-Jen Lin) wrote:
-
- >In C, usually we treat 1 as true and 0 as false.
-
- Not quite! It's NON-ZERO as true and 0 as false.
-
- >However, we usually use return(0) after normal end of an int
- >function and return(1) when some errors happen.
-
- The parens are redundant.
- return 0;
- is syntactically correct code.
-
- >Can some one tell me why we return a false value after normal
- >end of a function ?
-
- We don't. You are mixing levels of abstraction. That 0 can be
- considered false is irrelevant. It can also be considered as the NUL
- char in ASCII which is also irrelevant.
-
- If one is numbering error codes, one usually needs only one error
- code for success, but may need many for errors. 0 is a more distinct
- value: there are many positive numbers, but only one zero. e.g. A
- routine might return:
- 0 operation successful
- 1 file does not exist or is not accessible
- 2 file has internal consistency errors
- 3 out of memory
- 4 other failure
- and you would probably do different things to correct each error.
-
- >Thanks in advance.
-
- >Chih-Jen Lin
-
- Sincerely,
-
- Gene Wirchenko
-
- C Pronunciation Guide:
- y=x++; "wye equals ex plus plus semicolon"
- x=x++; "ex equals ex doublecross semicolon"
-
-